﻿using Demo.OrderService.Entities;
using Demo.OrderService.Services;
using Demo.OrderService.Services.Dtos;
using Microsoft.AspNetCore.Mvc;
using Servicecomb.Saga.Omega.Abstractions.Transaction;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Mvc;

namespace Demo.OrderService.Controllers;

/// <summary>
/// 订单控制器
/// </summary>
[ApiController]
[Route("api/app/order")]
public class OrderController : AbpController, IOrderService
{
    public IOrderService OrderService { get; set; }

    /// <summary>
    /// 添加订单
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns> 
    [HttpPost("create")]
    public async Task<ShopOrderDto> CreateAsync(ShopOrderDto input)
    {
        try
        {
            var result = await OrderService.CreateAsync(input);
            return result;
        }
        catch (Exception e)
        {

            throw;
        }
    }


    /// <summary>
    /// 创建订单
    /// </summary>
    /// <param name="orderDto"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpPost("createOrder")]
    [Compensable(nameof(DeleteOrder))]
    public async Task<ShopOrder> CreateOrderAsync(ShopOrderDto orderDto)
    {
        try
        {
            var result = await OrderService.CreateOrderAsync(orderDto);
            return result;
        }
        catch (Exception e)
        {

            throw;
        }
    }

    void DeleteOrder(ShopOrderDto orderDto) {

        try
        {
            var id = orderDto.SessionId;
        }
        catch (Exception e)
        {

            throw;
        }
    }


    /// <summary>
    /// 删除订单
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpDelete("id")]
    public Task DeleteAsync(Guid id)
    {
        throw new NotImplementedException();
    }

    /// <summary>
    /// 获取订单详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("id")]
    public async Task<ShopOrderDto> GetAsync(Guid id)
    {
        return await OrderService.GetAsync(id);
    }

    /// <summary>
    /// 订单列表
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpGet("list")]
    public async Task<PagedResultDto<ShopOrderDto>> GetListAsync(PagedAndSortedResultRequestDto input)
    {
        var list = await OrderService.GetListAsync(input);
        return list;
    }

    /// <summary>
    /// 添加订单
    /// </summary>
    /// <returns></returns>
    [HttpPost("Order")]
    //[Compensable(nameof(DeleteOrder))] // 调用删除订单方法
    public async Task<ShopOrderDto> OrderAsync(ShopOrderDto orderDto)
    {
        // 1、实现添加商品
        return await OrderService.CreateAsync(orderDto);
    }

    /// <summary>
    /// 更新订单
    /// </summary>
    /// <param name="id"></param>
    /// <param name="input"></param>
    /// <returns></returns>
    /// <exception cref="NotImplementedException"></exception>
    [HttpPut("updateOrder")]
    public Task<ShopOrderDto> UpdateAsync(Guid id, ShopOrderDto input)
    {
        throw new NotImplementedException();
    }

  
}
